package com.jzh.selfwallpaper.view.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.jzh.selfwallpaper.R;
import com.jzh.selfwallpaper.constant.Constant;
import com.jzh.selfwallpaper.entity.RaceLightConfig;
import com.jzh.selfwallpaper.view.adapter.ColorChooseAdapter;

public class RaceLightActivity extends BaseActivity {


    private GridView gv_choice_color;
    private EditText et_message, et_textSize;
    private TextView tv_topbar_title;
    private ImageView iv_topbar_back;
    private ColorChooseAdapter colorChooseAdapter;
    private int choosed_color = 0;
    private int[] colors = new int[]{R.color.A2, R.color.A11, R.color.A22, R.color.A23, R.color.A14,
            R.color.A1, R.color.A24, R.color.A8, R.color.A6, R.color.A10};

    private Button btn_start;

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {
            case R.id.btn_start:
                RaceLightConfig raceLightConfig = new RaceLightConfig();
                raceLightConfig.text = et_message.getText().toString();
                raceLightConfig.color = choosed_color;
                String str = et_textSize.getText().toString().trim();
                raceLightConfig.size = Float.valueOf(str == null ? "600" : str);
                //Log.i("mkmkmk", raceLightConfig == null ? "空" : raceLightConfig.toString());
                Intent intent = new Intent(RaceLightActivity.this, RaceLightPlayActivity.class);
                Bundle bundle = new Bundle();
                bundle.putParcelable(Constant.RACE_LIGHT_FLAG, raceLightConfig);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.iv_topbar_back:
                finish();
                break;
        }
    }

    @Override
    protected void init() {

    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_race_light;
    }

    @Override
    public void initView(View view) {

        gv_choice_color = view.findViewById(R.id.gv_choice_color);
        colorChooseAdapter = new ColorChooseAdapter(colors, this);
        gv_choice_color.setAdapter(colorChooseAdapter);
        et_message = (EditText) findViewById(R.id.edt_message);
        et_textSize = (EditText) findViewById(R.id.edt_textSize);
        et_textSize.setText(600 + "");
        btn_start = findViewById(R.id.btn_start);
        tv_topbar_title = findViewById(R.id.tv_topbar_title);
        tv_topbar_title.setVisibility(View.GONE);
        iv_topbar_back = findViewById(R.id.iv_topbar_back);
    }

    @Override
    public void setListener() {
        iv_topbar_back.setOnClickListener(this);
        btn_start.setOnClickListener(this);
        colorChooseAdapter.setOnGridViewClicked(new ColorChooseAdapter.OnGridViewClicked() {
            @Override
            public void onGridItemClicked(int position) {
                choosed_color = colors[position];
                colorChooseAdapter.notifyDataSetChanged();
                et_message.setTextColor(getResources().getColor(choosed_color));
            }
        });
    }

    @Override
    public void doBusiness(Context mContext) {

    }
}
